{{extend ("./layout.html")}}

{{#block ("body")}}
    <div class="panel panel-default">
                    <div class="panel-heading">
                        <ol class="breadcrumb">
                            <li><a href="#">首页</a></li>
                            <li><a href="#">学生管理</a></li>
                            <li class="active">学生列表</li>
                        </ol>
                    </div>
                    <div class="panel-heading">
                        <div class="input-group">
                            <span class="input-group-addon" id="basic-addon1">学生姓名</span>
                            <input type="text" class="form-control" id="studentName" placeholder="请输入学生姓名进行查询" aria-describedby="basic-addon1" style="width:200px;margin-right:10px;" value="{{keyword}}">
                            <input type="button" class="btn btn-success" onclick='search()' value="查找" style="margin-right:10px;">
                            <input type="button" class="btn btn-success" value="新增" onclick="window.location='/student/add'">
                        </div>
                    </div>
                    <div class="panel-body">
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th>姓名</th>
                                    <th>年龄</th>
                                    <th>性别</th>
                                    <th>手机号码</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                   {{#each(studentlist)}}
                                        <tr>
                                            <td>{{this.name}}</td>
                                            <td>{{this.age}}</td>
                                            <td>{{this.sex}}</td>
                                            <td>{{this.phone}}</td>
                                            <td>
                                                    <a href="javascript:window.location='/student/update/{{this._id}}'"class ="btn btn-success" >编辑</a> |

                                                    <input type="button" class ="btn btn-danger" onclick='dele("{{this._id}}")' value="删除">
                                            </td>
                                        </tr>
                                    {{/each}}
                            </tbody>
                        </table>
                    </div>
     </div>
<script>
    function dele(studentId){
        if(confirm("确定删除该条记录?")){
            $.getJSON({
                url:'/student/delect/'+studentId,
                success: function (json) {
                    console.log(json.message);
                    window.location='/student/info';
                }
            })
        }
    }
    function search(){
        var keyword = $("#studentName").val();

        window.location='/student/info?keyword='+keyword;

    }
</script>
{{/block}}
